//
//  RJCstationMapView.m
//  AirQuality
//
//  Created by Mac on 16/2/19.
//  Copyright © 2016年 Po. All rights reserved.
//

#import "RJCstationMapView.h"
#import "RJHomeTopMapModel.h"
#import "RJNetWork.h"

//#import <BaiduMapAPI/BMapKit.h>
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"
#import "UIImage+WebP.h"

#import "BMKPointAnnotation+color.h"
#import "RJHomeTopMapPointView.h"
#import "RJOutVC.h"
#import "RJLoadView.h"

@interface RJCstationMapView () <BMKMapViewDelegate, BMKLocationServiceDelegate>

@property (retain, nonatomic) BMKMapView * mapView;
@property (retain, nonatomic) BMKLocationService * locService;
@property (retain, nonatomic) BMKGroundOverlay * applyImage;
@property (retain, nonatomic) RJHomeTopMapModel * model;
@property (retain, nonatomic) UILabel * errorImageLabel;
@property (retain, nonatomic) NSMutableArray * overlayArray;

@property (retain, nonatomic) NSString * currentType;
@property (assign, nonatomic) BOOL isImage;
- (void)initData;
@property (assign) NSInteger flag;
@property (strong, nonatomic) NSMutableArray * subTitleArr , * mainTitle;           //副标题数组 主标题数组
@property (assign) NSInteger index;
@property (strong, nonatomic) NSString * currentPullution;
@end

@implementation RJCstationMapView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mapViewWillDisappear) name:@"MapViewWillDisappear"  object:nil];
        //        [self initData];
        //
        _index = 0;
        [self performSelector:@selector(mapViewDelay) withObject:nil afterDelay:0.0f];
        //        [self addSubview:[self getMapView]];
        //        [self setMapPostion];
    }
    return self;
}

- (void)mapViewDelay{
    _currentPullution = @"AQI";
    [self initData];
    [self addSubview:[self getMapView]];
    [self setMapPostion];
}

- (void)initData
{
    _isImage = NO;
    _model = [[RJHomeTopMapModel alloc] init];
    _overlayArray = [NSMutableArray array];
    [self initNet];
}

- (void)initNet
{
    if (_isImage) {
    } else {
        [self getRealAQINet];
    }
}

- (void)initNetWithCityName:(NSString *)cityName withCityCode:(NSString *)cityCode
{
    if (_isImage) {
    } else {
        [self getRealAQINetWithCityName:cityName withCityCode:cityCode];
    }
}


- (void)getRealAQINetWithCityName:(NSString *)cityName withCityCode:(NSString *)cityCode
{
    /**渲染点*/
//    NSArray * cityArr = @[@"成都",@"自贡",@"攀枝花",@"泸州"	,@"德阳",@"绵阳",@"广元",	@"遂宁",@"内江",@"乐山",@"南充",@"眉山"	,@"宜宾",@"广安",@"达州",@"雅安",@"巴中",@"资阳",@"马尔康",@"康定",@"西昌"];
//    NSArray * codeArr = @[@"5101",@"5103",@"5104",@"5105",@"5106",@"5107",@"5108",@"5109",@"5110",@"5111",@"5113",@"5114",@"5115",@"5116",@"5117",@"5118",@"5119",@"5120",@"5132",@"5133",@"5134"];
//    NSString * cityName , * cityCode;
//    cityName = [RJUserData defaultRJUserData].paoPaoName;
    if (cityName.length <= 0) {
//        cityName = [RJUserData defaultRJUserData].currentCity;
        NSRange shiString = [cityName rangeOfString:@"市"];
        NSRange xianString = [cityName rangeOfString:@"县"];
        if (shiString.location != NSNotFound) {
            cityName = [cityName substringWithRange:NSMakeRange(0, shiString.location)];
        }
        if (xianString.location != NSNotFound) {
            cityName = [cityName substringWithRange:NSMakeRange(0, xianString.location)];
        }
    }
//    NSInteger index = [cityArr indexOfObject:cityName];
//    cityCode = codeArr[index];
    //@"http://221.237.179.54:5119/publish/getCityInfoC?cityCode=5119"
    NSString * url = [NSString stringWithFormat:@"http://www.scnewair.cn:%@/publish/getCityInfoC?cityCode=%@",cityCode,cityCode];
     url = [NSString stringWithFormat:@"http://www.scnewair.cn:3389/publish/getCityInfoCForApp?cityCode=%@",cityCode];
    [RJNetWork myNetRequestWithAddress:url data:@{} completeBlock:^(id responseObject) {
        //        if ([RJUserData defaultRJUserData].isProvince) {
        //            _model.allAQIArray = [NSArray arrayWithArray:responseObject[@"data"]];
        //        } else {
        //            NSDictionary * columns = responseObject[@"columns"];
        //            NSDictionary * stationRealTimeAQ = columns[@"STATIONREALTIMEAQI"];
        //            _model.allAQIArray = [NSArray arrayWithArray:stationRealTimeAQ[@"data"]];
        //        }
        NSDictionary * columns = responseObject[@"columns"];
        NSDictionary * stationRealTimeAQ = columns[@"STATIONREALTIMEAQI"];
        _model.allAQIArray = [NSArray arrayWithArray:stationRealTimeAQ[@"data"]];
        _currentType = _currentPullution;
        [self changeMapWithType:_currentType];
    }failBlack:^(id response) {
        
    }];
}


- (void)getRealAQINet
{
    /**渲染点*/
    NSArray * cityArr = @[@"成都",@"自贡",@"攀枝花",@"泸州"	,@"德阳",@"绵阳",@"广元",	@"遂宁",@"内江",@"乐山",@"南充",@"眉山"	,@"宜宾",@"广安",@"达州",@"雅安",@"巴中",@"资阳",@"马尔康",@"康定",@"西昌"];
    NSArray * codeArr = @[@"5101",@"5103",@"5104",@"5105",@"5106",@"5107",@"5108",@"5109",@"5110",@"5111",@"5113",@"5114",@"5115",@"5116",@"5117",@"5118",@"5119",@"5120",@"5132",@"5133",@"5134"];
    NSString * cityName , * cityCode;
    cityName = [RJUserData defaultRJUserData].paoPaoName;
    if (cityName.length <= 0) {
        cityName = [RJUserData defaultRJUserData].currentCity;
        NSRange shiString = [cityName rangeOfString:@"市"];
        NSRange xianString = [cityName rangeOfString:@"县"];
        if (shiString.location != NSNotFound) {
            cityName = [cityName substringWithRange:NSMakeRange(0, shiString.location)];
        }
        if (xianString.location != NSNotFound) {
            cityName = [cityName substringWithRange:NSMakeRange(0, xianString.location)];
        }
    }
    NSInteger index = [cityArr indexOfObject:cityName];
    cityCode = codeArr[index];
    //@"http://221.237.179.54:5119/publish/getCityInfoC?cityCode=5119"
    NSString * url = [NSString stringWithFormat:@"http://www.scnewair.cn:%@/publish/getCityInfoC?cityCode=%@",cityCode,cityCode];
    url = [NSString stringWithFormat:@"http://www.scnewair.cn:3389/publish/getCityInfoCForApp?cityCode=%@",cityCode];
    [RJNetWork myNetRequestWithAddress:url data:@{} completeBlock:^(id responseObject) {
//        if ([RJUserData defaultRJUserData].isProvince) {
//            _model.allAQIArray = [NSArray arrayWithArray:responseObject[@"data"]];
//        } else {
//            NSDictionary * columns = responseObject[@"columns"];
//            NSDictionary * stationRealTimeAQ = columns[@"STATIONREALTIMEAQI"];
//            _model.allAQIArray = [NSArray arrayWithArray:stationRealTimeAQ[@"data"]];
//        }
        NSDictionary * columns = responseObject[@"columns"];
        NSDictionary * stationRealTimeAQ = columns[@"STATIONREALTIMEAQI"];
        _model.allAQIArray = [NSArray arrayWithArray:stationRealTimeAQ[@"data"]];
        _currentType = _currentPullution;
        [self changeMapWithType:_currentType];
    }failBlack:^(id response) {
        
    }];
}

- (BMKMapView *)getMapView
{
    if(!_mapView) {
        _mapView = [[BMKMapView alloc] initWithFrame:self.bounds];
        [_mapView setDelegate:self];
        [_mapView setShowsUserLocation:NO];     //是否显示定位图层
        [_mapView setZoomEnabled:YES];
        [_mapView setZoomEnabledWithTap:YES];
        [_mapView setShowMapScaleBar:NO];
        [_mapView setRotateEnabled:NO];
        [_locService startUserLocationService];
        [_mapView setUserTrackingMode:BMKUserTrackingModeNone];
        _mapView.mapType = BMKMapTypeStandard;
        _mapView.frame = self.bounds;
        _mapView.scrollEnabled = NO;
        _mapView.zoomEnabled = NO;
        _mapView.zoomEnabledWithTap = NO;
        _locService = [[BMKLocationService alloc]init];
       [_locService setDelegate:self];
    }
    return _mapView;
}

/**获取渲染图片*/
- (BMKGroundOverlay *)getApplyImage:(UIImage *)image
{
    if (!_applyImage) {
        CLLocationCoordinate2D coors;
        coors.latitude = 31.563526;
        coors.longitude = 104.172281;
        [_applyImage setAlpha:0.1f];
        _applyImage = [BMKGroundOverlay groundOverlayWithPosition:coors zoomLevel:12.0f anchor:CGPointMake(1.0f,0.0f) icon:image];
    }
    return _applyImage;
}
#pragma mark - function
- (void)reloadView:(BOOL)isPro cityName:(NSString *)cityName cityCode:(NSString *)cityCode
{
    [self setMapPostionWithCityName:cityName withCityCode:cityCode];
    [self initNetWithCityName:cityName withCityCode:cityCode];
}

- (void)setMapPostionWithCityName:(NSString *)cityName withCityCode:(NSString *)cityCode
{
    _flag = 0;
    //设置地图显示位置（默认为天安门）
    CLLocationCoordinate2D position;    //天府广场
    //    if ([RJUserData defaultRJUserData].isProvince) {
    //        position.latitude = 30.649628;
    //        position.longitude = 104.709657;
    //        BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(position, BMKCoordinateSpanMake(0.02f,0.02f));
    //        BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];
    //        [_mapView setRegion:adjustedRegion animated:NO];
    //        [_mapView setMinZoomLevel:7.5];
    //        [_mapView setMaxZoomLevel:15];
    //        [_mapView setZoomLevel:DeviceType >= 6 ? 8 : 7.5];
    //    } else {
    //        NSString * cityName = [RJUserData defaultRJUserData].paoPaoName;
    //        NSRange shiString = [cityName rangeOfString:@"市"];
    //        NSRange xianString = [cityName rangeOfString:@"县"];
    //        if (shiString.location != NSNotFound) {
    //            cityName = [cityName substringWithRange:NSMakeRange(0, shiString.location)];
    //        }
    //        if (xianString.location != NSNotFound) {
    //            cityName = [cityName substringWithRange:NSMakeRange(0, xianString.location)];
    //        }
//    NSString * cityName ;
//    cityName = [RJUserData defaultRJUserData].paoPaoName;
//    if (cityName.length <= 0) {
//        cityName = [RJUserData defaultRJUserData].currentCity;
//    }
    
    //        NSRange shiString = [cityName rangeOfString:@"市"];
    //        NSRange xianString = [cityName rangeOfString:@"县"];
    //        if (shiString.location != NSNotFound) {
    //            cityName = [cityName substringWithRange:NSMakeRange(0, shiString.location)];
    //        }
    NSDictionary * cityPostion = _model.cityPosition[cityName];
    CGFloat latitude = [cityPostion[@"latitude"] floatValue];
    CGFloat longitude = [cityPostion[@"longitude"] floatValue];
    latitude = [RJTools getCityCenterLatitudeWithCityName:cityName withLatitude:latitude];
    longitude = [RJTools getCityCenterLatitudeWithCityName:cityName withLongtitude:longitude];
    position.latitude = latitude;
    position.longitude = longitude;
    BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(position, BMKCoordinateSpanMake(0.06f,0.06f));
    BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];
    [_mapView setRegion:adjustedRegion animated:NO];
    [_mapView setMinZoomLevel:7.5];
    [_mapView setMaxZoomLevel:15];
    if ([cityName isEqualToString:@"广元"]) {
        [_mapView setZoomLevel:12.5];
    }else if ([cityName isEqualToString:@"巴中"]){
        [_mapView setZoomLevel:12.5];
    }else if([cityName isEqualToString:@"达州"]){
        [_mapView setZoomLevel:12];
    }else if ([cityName isEqualToString:@"南充"]){
        [_mapView setZoomLevel:12];
    }else
        [_mapView setZoomLevel:12];
    
}


/**设置位置*/
- (void)setMapPostion
{
    _flag = 0;
    //设置地图显示位置（默认为天安门）
    CLLocationCoordinate2D position;    //天府广场
//    if ([RJUserData defaultRJUserData].isProvince) {
//        position.latitude = 30.649628;
//        position.longitude = 104.709657;
//        BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(position, BMKCoordinateSpanMake(0.02f,0.02f));
//        BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];
//        [_mapView setRegion:adjustedRegion animated:NO];
//        [_mapView setMinZoomLevel:7.5];
//        [_mapView setMaxZoomLevel:15];
//        [_mapView setZoomLevel:DeviceType >= 6 ? 8 : 7.5];
//    } else {
//        NSString * cityName = [RJUserData defaultRJUserData].paoPaoName;
//        NSRange shiString = [cityName rangeOfString:@"市"];
//        NSRange xianString = [cityName rangeOfString:@"县"];
//        if (shiString.location != NSNotFound) {
//            cityName = [cityName substringWithRange:NSMakeRange(0, shiString.location)];
//        }
//        if (xianString.location != NSNotFound) {
//            cityName = [cityName substringWithRange:NSMakeRange(0, xianString.location)];
//        }
        NSString * cityName ;
        cityName = [RJUserData defaultRJUserData].paoPaoName;
        if (cityName.length <= 0) {
            cityName = [RJUserData defaultRJUserData].currentCity;
        }

//        NSRange shiString = [cityName rangeOfString:@"市"];
//        NSRange xianString = [cityName rangeOfString:@"县"];
//        if (shiString.location != NSNotFound) {
//            cityName = [cityName substringWithRange:NSMakeRange(0, shiString.location)];
//        }
        NSDictionary * cityPostion = _model.cityPosition[cityName];
        CGFloat latitude = [cityPostion[@"latitude"] floatValue];
        CGFloat longitude = [cityPostion[@"longitude"] floatValue];
        latitude = [RJTools getCityCenterLatitudeWithCityName:cityName withLatitude:latitude];
        longitude = [RJTools getCityCenterLatitudeWithCityName:cityName withLongtitude:longitude];
        position.latitude = latitude;
        position.longitude = longitude;
        BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(position, BMKCoordinateSpanMake(0.06f,0.06f));
        BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];
    [_mapView setRegion:adjustedRegion animated:NO];
    [_mapView setMinZoomLevel:7.5];
    [_mapView setMaxZoomLevel:15];
    if ([cityName isEqualToString:@"广元"]) {
        [_mapView setZoomLevel:12.5];
    }else if ([cityName isEqualToString:@"巴中"]){
        [_mapView setZoomLevel:12.5];
    }else if([cityName isEqualToString:@"达州"]){
        [_mapView setZoomLevel:12];
    }else if ([cityName isEqualToString:@"南充"]){
        [_mapView setZoomLevel:12];
    }else
    [_mapView setZoomLevel:12];
    
}

- (void)updateWithButtonString:(NSString *)title
{
    _currentType = title;
    [self changeMapWithType:_currentType];
}


- (void)changeMapWithType:(NSString *)type
{
    _subTitleArr = [NSMutableArray array];
    _mainTitle = [NSMutableArray array];
    _flag = 0;
    if (_isImage) {
        [self changeImageWithType:type];
    } else {
        [self changePointWithType:type];
    }
}

/**更改渲染点集合*/
- (void)changePointWithType:(NSString *)type
{
    _index = 0;
    _currentPullution = type;
    if ([_overlayArray count] != 0) {
        for (BMKAnnotationView * annotationView in _overlayArray) {
            [annotationView.paopaoView setHidden:YES];
            [annotationView removeFromSuperview];
        }
        [_overlayArray removeAllObjects];
        NSArray * array = [NSArray arrayWithArray:_mapView.overlays];
        [_mapView removeOverlays:array];
    }
    for (NSUInteger i = 0; i < _model.allAQIArray.count; i ++) {
        [self setAllStationWithCount:i type:type];
    }
}

/**省站地图*/
- (void)setAllStationWithCount:(NSUInteger)count type:(NSString *)type
{
    NSDictionary * columns = _model.allAQIArray[count][@"columns"];
    NSString * cityName = columns[@"STATIONNAME"];
    NSString * numString,* colorRank;
    if ([type isEqualToString:@"AQI"]) {
        numString = columns[type];
        colorRank = columns[type];
    } else {
        colorRank = columns[[NSString stringWithFormat:@"I%@",type]];
        numString = columns[type];
    }
    NSString * numStr = [NSString stringWithFormat:@"%@",numString];
    NSNumber * num;
    if([numStr  isEqual: @"0.0"]||[numStr isEqualToString:@""] || [numStr isEqualToString:@"—"] || [numStr isEqualToString:@"(null)"]){
        num = @(6000);
    } else {
        num = @([numString floatValue]);
    }
    
    CLLocationCoordinate2D coor;
//    if ([RJUserData defaultRJUserData].isProvince) {
//        NSDictionary * position = _model.cityPosition[cityName];
//        coor.latitude = [position[@"latitude"] floatValue];
//        coor.longitude = [position[@"longitude"] floatValue];
//    } else {
//        coor.latitude = [columns[@"LAT"] floatValue];
//        coor.longitude = [columns[@"LNG"] floatValue];
//    }
    if (_index%2 == 0) {
        if ([cityName isEqualToString:@"苏山坪"]) {
            coor.latitude = [columns[@"LAT"] floatValue]+0.06;
            coor.longitude = [columns[@"LNG"] floatValue]+0.05;
        }else{
            coor.latitude = [RJTools getLatitudeWithCityName:cityName withLatitude:[columns[@"LAT"] floatValue]+0.02];
            coor.longitude = [RJTools getLatitudeWithCityName:cityName withLongtitude:[columns[@"LNG"] floatValue]+0.02];
        }
    }else{
        if ([cityName isEqualToString:@"灵岩寺"]) {
            coor.latitude = [columns[@"LAT"] floatValue]-0.3;
            coor.longitude = [columns[@"LNG"] floatValue]+0.32;
        }else{
            coor.latitude = [RJTools getLatitudeWithCityName:cityName withLatitude:[columns[@"LAT"] floatValue]-0.02];
            coor.longitude = [RJTools getLatitudeWithCityName:cityName withLongtitude:[columns[@"LNG"] floatValue]-0.02];
        }
    }
    _index ++;
    BMKPointAnnotation * circles = [[BMKPointAnnotation alloc]init];
    [circles setCoordinate:coor];
    [circles setAirRankColor:[self getMapBoxColor:[colorRank floatValue]]];
    if ([numStr  isEqual: @"0.0"]||[numStr isEqualToString:@""] || [numStr isEqualToString:@"—"] || [numStr isEqualToString:@"(null)"]) {
        [circles setAirRankColor:[UIColor grayColor]];
    }
    //    [circles setSubtitle:[NSString stringWithFormat:@"%@",numString]];
    [circles setTitle:cityName];
    if ([type isEqualToString:@"CO"]) {
        CGFloat coValue = [numString floatValue];
       [_subTitleArr addObject:[NSString stringWithFormat:@"%.1f",coValue]];
    }else{
       [_subTitleArr addObject:[NSString stringWithFormat:@"%@",numString]];
    }
    [_mainTitle addObject:cityName];
    //  [circles setTitle:[NSString stringWithFormat:@"%@",numString]];
    [_mapView addAnnotation:circles];
}

/**渲染图片获取*/
- (void)changeImageWithType:(NSString *)type
{
    [[SDImageCache sharedImageCache] clearDisk];
    if (_applyImage) {
        [_mapView removeOverlay:_applyImage];
        _applyImage = nil;
    }
    
    UIImageView * imageSrc = [[UIImageView alloc] initWithFrame:self.bounds];
    [self addSubview:imageSrc];
    [imageSrc sd_setImageWithURL:[NSURL URLWithString:applyImageURL([_model.applyImageNameDic objectForKey:type])] placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        //判断是否可以获取渲染
        if (!image) {
            if (!_errorImageLabel) {
                _errorImageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
                [_errorImageLabel setCenter:self.center];
                [_errorImageLabel setText:@"获取渲染图失败,请稍后再试."];
                [_errorImageLabel setTextColor:[UIColor yellowColor]];
                [_errorImageLabel setTextAlignment:NSTextAlignmentCenter];
                [_errorImageLabel setFont:[UIFont systemFontOfSize:14]];
                [self addSubview:_errorImageLabel];
            }
        } else {
            if (_errorImageLabel) {
                [_errorImageLabel removeFromSuperview];
            }
            [_mapView addOverlay:[self getApplyImage:image]];
        }
        [imageSrc removeFromSuperview];
    }];
}
#pragma mark - mapView
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay
{
    if ([overlay isKindOfClass:[BMKGroundOverlay class]])
    {
        BMKGroundOverlayView* groundView = [[BMKGroundOverlayView alloc] initWithOverlay:overlay];
        return groundView;
    }
    return nil;
}

/**标注设置*/
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    NSString *AnnotationViewID = @"cityAir";
    RJHomeTopMapPointView *annotationView = (RJHomeTopMapPointView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
    
    if (annotationView == nil) {
        annotationView = [[RJHomeTopMapPointView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
        CGRect rect = CGRectMake(0, 0, DeviceType > 6 ? 60 : 50, DeviceType > 6 ? 25 :20);
        [annotationView setFrame:rect];
        // 设置颜色
        annotationView.annotation = annotation;
        //        annotationView.image = [UIImage imageNamed:DeviceType > 6 ? @"alphaBackBig" : @"alphaBackMap"];
        annotationView.backgroundColor = [((BMKPointAnnotation *)annotation) airRankColor];
        NSString * subtitle = _subTitleArr[_flag];
        NSString * mainTitle = _mainTitle[_flag];
        [annotationView setNum:subtitle];
        _flag ++;
        // 设置可拖拽
        annotationView.draggable = NO;
        CGPoint point = annotationView.centerOffset;
        point.y += 15;
        [annotationView setCenterOffset:point];
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, 80, 39)];
        imageView.image = [UIImage imageNamed:@"popcloud_for_map"];
        imageView.userInteractionEnabled = YES;
        UIButton * button = [[UIButton alloc] init];
//        if ([RJUserData defaultRJUserData].isProvince) {
//            button.frame = CGRectMake(5, -3, 50, 39);
//        }else{
//            button.frame = CGRectMake(10, -3, 60, 39);
//        }
        button.frame = CGRectMake(10, -3, 60, 39);
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button setTitle:mainTitle forState:UIControlStateNormal];
        [button setTitleColor:GetRGBColor(84, 84, 84, 1) forState:UIControlStateNormal];
        [imageView addSubview:button];
        UIImageView * infoImage = [[UIImageView alloc] init];
        infoImage.frame = CGRectMake(51, 8, 15, 15);
        infoImage.image = [UIImage imageNamed:@"info_icon_2"];
//        if ([RJUserData defaultRJUserData].isProvince) {
//            [imageView addSubview:infoImage];
//            button.userInteractionEnabled = YES;
//        }else{
//            button.userInteractionEnabled = NO;
//        }
        annotationView.paopaoView = [[BMKActionPaopaoView alloc] initWithCustomView:imageView];
        [_overlayArray addObject:annotationView];
    }
    return annotationView;
}

- (UIColor *)getMapBoxColor:(NSInteger)num
{
    
    NSInteger rank = num / 50;
    if (rank > 5) {
        rank = 5;
    }
    
    if (num % 50 == 0) {
        rank -- ;
    }
    if (num == 50) {
        ;
    }
    
    if (rank > 5 || rank < 0) {
        rank = 5;
    }
    if (num == 6000) {
        rank = 6;
    }
    NSArray * colors = @[
                         GetRGBColor(0, 228, 0, 1),
                         GetRGBColor(253, 198, 30, 1),
                         GetRGBColor(255, 126, 0, 1),
                         GetRGBColor(255, 0, 0, 1),
                         GetRGBColor(153, 0, 76, 1),
                         GetRGBColor(126, 0, 35, 1),
                         GetRGBColor(164, 164, 166, 1)                         ];
    return colors[rank];
}

@end
